// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package com.myplans.remote;

import java.util.List;

import com.myplans.model.User;
import com.myplans.model.UserDao;
import com.myplans.vo.PlanValue;
import com.myplans.vo.UserValue;

/**
 * @see com.myplans.remote.UserService
 */
public class UserServiceImpl
    extends com.myplans.remote.UserServiceBase
{

    /**
     * @see com.myplans.remote.UserService#createUser(com.myplans.vo.UserValue)
     */
    protected  com.myplans.vo.UserValue handleCreateUser(com.myplans.vo.UserValue user)
        throws java.lang.Exception
    {
        return (UserValue)getUserDao().create(UserDao.TRANSFORM_USERVALUE, getUserDao().userValueToEntity(user));
    }

    /**
     * @see com.myplans.remote.UserService#getUsers(com.myplans.vo.UserValue)
     */
    protected  java.util.List<com.myplans.vo.UserValue> handleGetUsers(com.myplans.criteria.UserSearchCriteria searchCriteria)
        throws java.lang.Exception
    {
        return getUserDao().getUsers(searchCriteria);
    }

	@Override
	protected UserValue handleUpdateUser(UserValue user) throws Exception {
		getUserDao().update(getUserDao().userValueToEntity(user));
		return user;
	}

	@Override
	protected UserValue handleCreatePlanForUser(PlanValue planValue,
			UserValue userValue) throws Exception {
		return getUserDao().createPlanForUser(planValue, userValue);
	}

	@Override
	protected List<PlanValue> handleGetPlansForUser(UserValue userValue)
			throws Exception {
		return getUserDao().getPlansForUser(userValue);
	}

	@Override
	protected UserValue handleDeletePlanForUser(PlanValue planValue,
			UserValue userValue) throws Exception {
		User userEntity = getUserDao().load(userValue.getId());
		
		userEntity.getPlans().remove(getPlanDao().load(planValue.getId()));
		
		return userValue;
	}

	@Override
	protected List<UserValue> handleGetSubscriptionsForUser(UserValue user)
			throws Exception {
		return getUserDao().getSubscriptionsForUser(user);
	}

	@Override
	protected UserValue handleCreateSubscriptionForUser(UserValue subscription,
			UserValue user) throws Exception {
		return getUserDao().createSubscriptionForUser(subscription, user);
	}

	@Override
	protected UserValue handleDeleteSubscriptionForUser(UserValue subscription,
			UserValue user) throws Exception {
		return getUserDao().deleteSubscriptionForUser(subscription, user);
	}

}